package cn.dota2info.elk.Service;


import cn.dota2info.elk.dao.ElkDocDao;
import cn.dota2info.elk.entity.BaseSearchParam;
import cn.dota2info.elk.entity.Book;
import org.elasticsearch.action.index.IndexResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private ElkDocDao elkDao;

    public String insert(Book book){
        return elkDao.insertObject(book,"book","doc",null).getId();
    }

    public Book get(Integer id){
        return (Book) elkDao.getObject("book","doc",Integer.toString(id),Book.class);
    }
    public boolean delete(Integer id){
        return  elkDao.deleteObject("book","doc",Integer.toString(id));
    }
    public Long update(Book book){
        return elkDao.updateObject(book,"book","doc").getVersion();
    }
    public List<Book> getAllBook(BaseSearchParam param) throws Exception {
        return elkDao.getAll("book","doc",Book.class,param);
    }
}
